<template>
    <div id="app">
        <keep-alive>
            <router-view @installPageMessage="installPageMessage" v-if="$route.meta.keepAlive"></router-view>
        </keep-alive>
        <transition name="classfiyIndex">
            <router-view @installPageMessage="installPageMessage" v-if="!$route.meta.keepAlive"></router-view>
        </transition>
        <div v-if="restools" class="restools">
            <img @click="restools = false,toolsPassword =''" style="position:absolute;right:10px;top:10px;cursor:pointer;" src="../resource/assets/img/close.png" alt="">
            <input class="toolsPassword" v-model="toolsPassword" @keyup.enter="openDevTools" autofocus="autofocus" type="password" placeholder="输入暗号" />
            <button class="openTools" @click="openDevTools">打开调试窗口</button>
        </div>
    </div>
</template>

<script>
export default {
    name: 'App',
    created () {
    },
    data () {
        return {
            restools:false,
            toolsPassword:'',
        }
    },
    mounted () {
        let options = {
            title: '加载资源中',
            progress: false,
            full: true,
        }
        this.loadingMask = this.$loadingmask(options)
        setTimeout(() => {
            this.installPageMessage().then(() => {
                this.$router.push({ name: 'HomePage' })
            })
        }, 0);
    },
    methods: {
        installPageMessage () {
            return new Promise(res => {
                window.document.onselectstart = () => false
                window.document.ondragstart = () => false
                this.initGlobalDir()
                let that = this;
                document.onkeydown = function (event) {
                    if (event.altKey && event.shiftKey && event.key == 'F12') {
                        that.restools = true
                        // that.$electron.remote.getCurrentWindow().webContents.openDevTools();
                        // console.log(that.$electron.remote.app.getAppPath());
                    }
                }
                window.document.addEventListener('mousemove', this.checkSuportTouch)
                res()
            })
        },
        openDevTools(){
            let that = this;
            if (this.toolsPassword === 'xzsmbos') {
                that.toolsPassword = ''
                that.restools = false
                that.$electron.remote.getCurrentWindow().webContents.openDevTools();
            }
        },
        checkSuportTouch (e) {
            window.isTouchScreen = true
            window.document.removeEventListener('mousemove', this.checkSuportTouch)
        },
        initGlobalDir () {
            const path = require('path');
            let that = this;
            //全局存储数据目录
            let dataDir = this.$readIniFile('data', 'dataDir');
            if (dataDir === "self") {//代表是当前目录
                if (process.env.NODE_ENV === 'production') {
                    window.$DATADIR = path.dirname(process.execPath) + '/resources/data/';
                } else {
                    window.$DATADIR = './data/';
                }
            } else if (dataDir === "low-update") {
                window.$DATADIR = path.dirname(process.execPath) + '/html/';
            } else {
                window.$DATADIR = dataDir;
            }
            //初始化dbPath
            let dbPath = ""
            if (process.env.NODE_ENV === 'production') {
                dbPath = window.$DATADIR + that.$CONST.global.db;
            } else {
                dbPath = window.$DATADIR + that.$CONST.global.dbTest;
            }
            window.$DBDIR = dbPath;
        },
    }
};
</script>

<style lang="scss">
.classfiyIndex-enter-active,
.classfiyIndex-leave-active {
    transition: all 0.5s ease-out;
}
.classfiyIndex-enter,
.classfiyIndex-leave-to {
    opacity: 0;
    // transform: translateY(-50px);
}
html,
body {
    margin: 0;
    padding: 0;
}
#app {
    margin: 0;
    padding: 0;
}
button {
    border: none;
}
.restools{
    background: linear-gradient(#ccf0ff, #8fc8e0);
    width: 500px;
    height: 300px;
    position: absolute;
    top: calc(50vh - 150px);
    left:calc(50vw - 250px);
    z-index: 10000!important;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-radius: 8px;
    .toolsPassword{
        border-radius: 4px;
        width: 300px;
        height: 60px !important;
        font-size: 20px;
        background: rgb(236, 240, 240);
    }
    .openTools{
        margin-top: 60px;
        width:200px;
        height:60px;
        border-radius:4px;
        border: none;
        color:#fff;
        font-size: 20px;
        background-color: #63b4d6;
        cursor: pointer;
    }
}
</style>
